<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml"
      xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>大区应收</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
          name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <script src="https://file.ggxqce.com/web/vue.min.js"></script>
    <style>
        body, html {
            width: 100%;
            margin: 0;
            font-family: "微软雅黑";
        }

        #allmap, #allmap2 {
            /*width: 100%;*/
            height: 300px;
            overflow: hidden;
            margin: 0;
            font-family: "微软雅黑";
        }

        [v-cloak] {
            display: none;
        }

        * {
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
            font-size: 12px;
        }

        body {
            margin: 1px;
            background: #ffffff;
        }

        .boxBoy {
            background: #fff;
        }

        table {
            border-spacing: 0;
            border-collapse: collapse;
            display: table;
        }

        .weather {
            text-align: center;
            font-size: 16px;
            /*position: absolute;*/
            top: 5px;
            line-height: 30px;
            float: left;
        }

        th {
            font-weight: normal;
        }

        table.text-center, table.text-center td, table.text-center th {
            text-align: center;
            font-size: 12px;
            margin-top: -1px;
        }

        .table-bordered > thead > tr > th, .table-bordered > tbody > tr > th, .table-bordered > tfoot > tr > th, .table-bordered > thead > tr > td, .table-bordered > tbody > tr > td, .table-bordered > tfoot > tr > td {
            border: 1px solid #cbcbcd;
            height: 28px;
            position: relative;
            color: #333;
            padding: 0 4px;
        }

        table th {
            background: #f8f8f8;
        }

        .table-bordered {
            border: 1px solid #cbcbcd;
        }

        .table {
            width: 100%;
            max-width: 100%;
        }

        .hidden {
            display: none;
        }

        .lineOne, .lineTwo {
            text-align: left;
        }

        .tdColor {
            background-color: #f8f8f8;
            font-weight: normal;
        }

        .lineOne span {
            max-height: 24px;
            line-height: 24px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            text-align: left;
        }

        .lineTwo span {
            max-height: 55px;
            line-height: 16px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 3;
            text-align: left;
            padding: 5px;

        }

        .div-td-content-more {
            position: absolute;
            height: auto;
            z-index: 999;
            line-height: 20px;
            background-color: #d3e8fd;
            padding: 8px 6px;
            border: 1px solid #e8e8ea;
            display: none;
        }

        .div-td-content-more i {
            width: 15px;
            height: 12px;
            background: url("/dist/img/more-icon.png");
            position: absolute;
            left: 50px;
            top: -12px;
        }

        .clear {
            clear: both
        }

        .boxItem {
            width: 100%;
            margin-top: 5px;
            background: inherit;
            /*background-color: rgba(255, 255, 255, 1);*/
            border: none;
            position: relative;
        }

        .boxItemTitle {
            color: #000;
            font-size: 22px;
            font-weight: bold;
            margin-bottom: 6px;
            text-align: center;
        }

        .home {
            font-size: 14px;
            font-weight: bold;
            margin-bottom: 10px;
            height: 14px;
            line-height: 14px;
            text-align: center;
        }

        .dian-icon {
            background: url("/dist/img/dian.png") no-repeat;
            background-size: cover;
            width: 14px;
            height: 14px;
            display: inline-block;
        }

        .jiaobiao, .jiaobiaoNew {
            position: relative;
        }

        .jiaobiao i {
            display: block;
            width: 0;
            height: 0;
            border-width: 0px 0 12px 12px;
            border-style: solid;
            border-color: transparent transparent transparent #2a8cec;
            position: absolute;
            top: 0px;
            left: 0px;
        }

        .jiaobiaoNew i {
            display: block;
            width: 12px;
            height: 12px;
            background: url("/dist/img/newLog2.png");
            background-size: 100% 100%;
            position: absolute;
            top: 0px;
            left: 0px;
        }

        .lineImg {
            padding-top: 5px !important;
            padding-bottom: 5px !important;
        }

        .lineImg img {
            height: 45px;
            width: 45px;
            float: left;
            margin: 10px;
            object-fit: cover;
        }

        .newCustomer {
            background: url(/dist/img/new.png) no-repeat;
            background-size: cover;
            width: 20px;
            height: 20px;
            right: 0;
            top: 2px;
            position: absolute;
        }

        .wajueji {
            padding-left: 140px;
            background: url("/dist/img/wajueji.png") no-repeat;
            background-size: 120px 88px;
            height: 88px;
            line-height: 88px;
            color: red;
            font-size: 14px;
            font-weight: bold;
            margin-left: 50px;
        }

        .qipao {
            /*background: url(/dist/img/qipao.png);*/
            background-size: 100% 100%;
            height: 88px;
            /* padding: 0 20px; */
            padding-left: 20px;
            /*padding-right: 20px;*/
            color: red;
            line-height: 88px;
            float: left;
            font-size: 14px;
            font-weight: bold;
        }

        .plan1 {
            background: url("/dist/img/plan1.png") no-repeat center center;
            background-size: 100%;
        }

        .plan2 {
            background: url("/dist/img/plan2.png") no-repeat center center;
            background-size: 100%;
        }

        .plan3 {
            background: url("/dist/img/plan3.png") no-repeat center center;
            background-size: 100%;
        }

        .boxItemTitleNotice {
            color: red;
            font-size: 22px;
            font-weight: bold;
            margin-bottom: 10px;
            text-align: center;
        }

        .boxItemTitleNotice i {
            background: url("/dist/img/jg.png") no-repeat center center;
            height: 22px;
            width: 22px;
            background-size: cover;
            display: inline-block;
            margin-bottom: -3px;
            margin-left: 5px;
        }

        .boxItemTitleNoticeTime {
            color: red;
            font-size: 20px;
            font-weight: bold;
            margin-bottom: 10px;
            text-align: center;
        }

        .boxItemTitleNoticeTime i {
            background: url("/dist/img/jg.png") no-repeat center center;
            height: 16px;
            width: 16px;
            background-size: cover;
            display: inline-block;
            margin-bottom: -3px;
            margin-left: 5px;
        }

        .search-button {
            width: 14px;
            height: 14px;
            background-image: url(/dist/img/glass.jpg);
            border: 0 none;
            cursor: pointer;
            margin-top: 0px;
        }

        input[type=button] {
            outline: none;
        }

        .oaBtn {
            background: url(/dist/img/btn-bj2.png) repeat-y !important;
            background-size: 100% 100% !important;
            color: #fff !important;
        }

        .btn-group-sm > .btn, .btn-sm {
            padding: 2px 10px;
        }

        .btn {
            border-radius: 3px;
            -webkit-box-shadow: none;
            box-shadow: none;
            border: 1px solid transparent;
        }

        .pull-right {
            float: right !important;
        }

        .blue {
            color: #39c;
        }

        .red {
            color: #e03800;
        }

        .weather img {
            height: 30px;
            width: 30px;
            float: left;
        }

        .templateStyle {
            margin-top: 10px;
            margin-left: 10px;
            margin-right: 10px;
        }

        .line {
            border-bottom: 4px solid #2a8cec;
        }

        .tryStyle {
            width: 34px;
            height: 17px;
            line-height: 17px;
            font-size: 12px;
            top: 0px;
            right: -3px;
            position: absolute;
            border-radius: 50px;
            margin-top: 4px;
            background: #ff131c;
            color: #fff;
            margin-right: -2px;
            transform: scale(0.7);
        }

    </style>
</head>
<body>
<section class="content" id="app" v-cloak>
    <div class="div-td-content-more"><i></i></div>
    <div class="templateStyle" v-if="list&&list.length>0">
        <table class="table table-bordered text-center table-width">
            <tbody>
            <tr>
                <td class="tdColor" style="width: 16%">客户</td>
                <td class="tdColor" style="width: 21%">到期日期</td>
                <td class="tdColor" style="width: 21%">到期金额</td>
                <td class="tdColor" style="width: 21%">逾期罚息</td>
                <th class="tdColor" style="width: 21%">合计</th>
            </tr>
            <tr v-for="(item,i) in tablesMergeCell(list)">
                <td class="lineOne" style="background-color: white;" :rowspan="item.buyerspan"
                    :class="{hidden: item.buyerdis}">
                            <span style="color:#2a8cec;cursor: pointer;text-align: center;"
                                  @click="goDetail('look',item)">
                                {{item.buyer}}
                            </span>
                </td>
                <td style="text-align: left !important;padding-left: 10px">
                    <span>{{item.repaymentDate.substring(5)}}</span>
                    <span style="text-align: center"
                          v-if="(Number(item.overduePenalty)>0||Number(item.remainingArrears)>0)&&compareFiveDate(item.repaymentDate)<0"
                          class="tryStyle">逾期</span>
                    <span v-else-if="Number(item.total)>0 && Number(item.overduePenalty)==0"
                          class="tryStyle"
                          style="background: #2a8cec;color: #fff;text-align: center">到期</span>
                </td>
                <td :style="item.remainingArrears?'text-align: right':'text-align: right'"
                    v-if="(item.overduePenalty && Number(item.overduePenalty)>0)||(item.remainingArrears && Number(item.remainingArrears)>0)">
                    <span class="lineOne">{{item.remainingArrears ?fmoney(item.remainingArrears):'-'}}</span>
                </td>
                <td v-else :style="item.total?'text-align: right':'text-align: right'">
                    <span>{{item.total ? fmoney(item.total) :'-'}}</span>
                </td>
                <td :style="item.overduePenalty ? 'text-align: right':'text-align: right'">
                    <span class="lineOne"
                          v-if="(Number(item.overduePenalty)>0||Number(item.remainingArrears)>0)&&compareFiveDate(item.repaymentDate)<0"> {{item.overduePenalty? fmoney(item.overduePenalty):'未知'}}</span>

                    <span class="lineOne" v-else> {{item.overduePenalty? fmoney(item.overduePenalty):'-'}}</span>
                </td>
                <td :style="item.newMoney? 'text-align: right':'text-align: right'" :rowspan="item.buyerspan"
                    :class="{hidden: item.buyerdis}">
                    {{item.newMoney? fmoney(item.newMoney):'-'}}
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div v-else>
        <div v-if="returnFlag"
        >
            <div style="margin: 0 auto;color: #999999;text-align: center;margin-top: 100px;font-size: 22px;"
                 v-if="roleName == '大区经理' || roleName == '区域经理' || roleName == '区域支持' || roleName == '销售管理' || roleName == '集团销售管理'|| roleName == '后台管理'">
                暂无逾期或到期
            </div>
            <div style="margin: 0 auto;color: #999999;text-align: center;margin-top: 100px;font-size: 22px;"
                 v-else>
                暂无逾期
            </div>
        </div>
    </div>
    <div style="margin-bottom: 15px;"></div>
</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oaApp.js"></script>
<!--插件JS-->
<script src="/dist/plugins/scroll/myScroll.js"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script src="/dist/plugins/select2/select2.full.min.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script>
    $(function () {
        $("body").on("click", ".lineOne,.lineTwo", function (e) {
            if ($(".div-td-content-more").is(":hidden")) {
                var text = $(this).text();
                if (text != "") {
                    text = "<i></i>" + text;
                    $(".div-td-content-more").html(text).css({
                        "width": $(this).outerWidth() + "px",
                        "left": $(this).offset().left,
                        "top": ($(this).offset().top + $(this).outerHeight()) + "px"
                    }).show();
                    e.stopPropagation();
                }
            } else {
                $(".div-td-content-more").hide();
            }
        });
        $("body").on("click", ".div-td-content-more", function (e) {
            e.stopPropagation();
        });
        $("body").on("click", function () {
            $(".div-td-content-more").hide();
        });
    });
</script>
<script>
    $.ajaxSetup({
        global: true,
        type: "POST",
        cache: false,
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        beforeSend: function () {
        },
        complete: function () {

        },
        error: function (e) {
            alert('error' + e.responseText);
        }
    });
    $.extend($.wyui, {
        postMethod: function (url, data, callback, sync, id) {
            if (!id) {
                id = "#app"
            }
            $.ajax({
                url: server.ip + url,
                async: sync ? false : true,
                data: JSON.stringify(data),
                beforeSend: function () {

                },
                complete: function () {
                    setTimeout(function () {
                    }, 1000);

                },
                success: function (r) {
                    if (!r.e.code) {
                        callback(r.data.sendData);
                    } else {
                        alert(r.e.desc);
                    }
                },
                error: function (e) {
                    alert(url + e.responseText);
                }
            });
        },
    });
</script>
<script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data: {
            rightOp: [],//权限列表
            haveSettle: false,
            list: [],
            returnFlag: false,
            roleName: getUrlParamObj().roleName,
            pageType: getUrlParamObj().pageType,
            searchParams: {
                auditFlag: 1,
                haveDelivery: 1,
                haveSettle: 0,
                userId: getUrlParamObj().userId,
                customerKeyId: '',
                createUserId: '',
                customerKey: '',
                createUserName: '',
            },
        },
        methods: {
            getNowDate: function () {
                var now = new Date();
                var year = now.getFullYear();
                var month = (now.getMonth() + 1).toString();
                var day = (now.getDate()).toString();
                var hour = (now.getHours()).toString();
                var minute = (now.getMinutes()).toString();
                var second = (now.getSeconds()).toString();
                if (month.length == 1) {
                    month = "0" + month;
                }
                if (day.length == 1) {
                    day = "0" + day;
                }
                if (hour.length == 1) {
                    hour = "0" + hour;
                }
                if (minute.length == 1) {
                    minute = "0" + minute;
                }
                if (second.length == 1) {
                    second = "0" + second;
                }
                var dateTime = year + "-" + month + "-" + day;
                return dateTime;
            },
            compareFiveDate: function (ydDate) {
                var aDate = new Date(this.getNowDate()); // 通过日期字符串，初始化第一个日期对象
                var bDate = new Date(ydDate); // 同上，初始化第二个日期对象
                var aDay = 24 * 60 * 60 * 1000; // 完整一天有24小时，将小时换算成毫秒时间戳
                var diffDay = (bDate - aDate) / aDay; // 计算间隔天数（注意日期隐式转换）
                console.log(diffDay); // 2，23日-25日间隔2天
                return diffDay;
            },
            //合并单元格
            tablesMergeCell: function (list) {
                if (list != undefined && list && list.length > 0) {
                    for (field in list[0]) {
                        var k = 0;
                        while (k < list.length) {
                            list[k][field + 'span'] = 1;
                            list[k][field + 'dis'] = false;
                            for (var i = k + 1; i <= list.length - 1; i++) {
                                if (list[k][field] == list[i][field] && list[k][field] != '') {
                                    list[k][field + 'span']++;
                                    list[k][field + 'dis'] = false;
                                    list[i][field + 'span'] = 1;
                                    list[i][field + 'dis'] = true;
                                } else {
                                    break;
                                }
                            }
                            k = i;
                        }
                    }
                }
                return list;
            },
            //js取当天日期的前五天
            getBeforeDate: function (n) {
                var n = n;
                var d = new Date();
                var year = d.getFullYear();
                var mon = d.getMonth() + 1;
                var day = d.getDate();
                if (day <= n) {
                    if (mon > 1) {
                        mon = mon - 1;
                    }
                    else {
                        year = year - 1;
                        mon = 12;
                    }
                }
                d.setDate(d.getDate() - n);
                year = d.getFullYear();
                mon = d.getMonth() + 1;
                day = d.getDate();
                s = year + "-" + (mon < 10 ? ('0' + mon) : mon) + "-" + (day < 10 ? ('0' + day) : day);
                return s;
            },
            getList: function () {
                if (this.haveSettle) {
                    this.searchParams.haveSettle = ""
                } else {
                    this.searchParams.haveSettle = 0
                }
                var that = this;
                var dialog = {
                    dialog: 'show'
                }
                prompt(JSON.stringify(dialog))
                $.wyui.postMethod(urlConfig.newDaQuReportForm.selectContractAccountListApp, {
                    auditFlag: 1,
                    haveDelivery: 1,
                    haveSettle: 0,
                    userId: getUrlParamObj().userId,
                    customerKeyId: '',
                    createUserId: '',
                    customerKey: '',
                    createUserName: '',
                    companyId: getUrlParamObj().isZongJian == 2 ? getUrlParamObj().companyId : ''
                }, function (data) {
                    console.log(data.records)

                    var list1 = [];
                    for (var i = 0; i < data.records.length; i++) {
                        if (that.roleName == '大区经理' || that.roleName == '区域经理' || that.roleName == '区域支持' || that.roleName == '销售管理' || that.roleName == '集团销售管理'|| that.roleName == '后台管理') {
                            if (data.records[i].repaymentDate && data.records[i].haveDsdf == '0' && (data.records[i].type != '2' && data.records[i].type != '4')) {
                                list1.push(data.records[i])
                            }
                            if (data.records[i].repaymentDate && data.records[i].haveDsdf == '1' && (data.records[i].type != '10' && data.records[i].type != '12')) {
                                list1.push(data.records[i])
                            }
                        } else {
                            if ((Number(data.records[i].overduePenalty) > 0 || Number(data.records[i].remainingArrears) > 0)&&that.compareFiveDate(data.records[i].repaymentDate)<0) {
                                if (data.records[i].repaymentDate && data.records[i].haveDsdf == '0' && (data.records[i].type != '2' && data.records[i].type != '4')) {
                                    list1.push(data.records[i])
                                }
                                if (data.records[i].repaymentDate && data.records[i].haveDsdf == '1' && (data.records[i].type != '10' && data.records[i].type != '12')) {
                                    list1.push(data.records[i])
                                }
                            }

                        }
                    }
                    for (var a = 0; a < list1.length; a++) {
                        var item = list1[a];
                        if (item.overduePenalty && Number(item.overduePenalty) > 0 || item.remainingArrears && Number(item.remainingArrears) > 0) {
                            item.count = Number(item.remainingArrears) + Number(item.overduePenalty)
                        } else {
                            item.count = Number(item.total) + Number(item.overduePenalty)
                        }
                    }

                    for (var a = 0; a < list1.length; a++) {
                        var newMoney = list1[a].count;
                        for (var b = 0; b < list1.length; b++) {
                            if (list1[a].buyer == list1[b].buyer && list1[a].id == list1[b].id && a != b) {
                                newMoney += Number(list1[b].count)
                            }
                        }
                        list1[a].newMoney = newMoney;
                    }
                    that.list = list1;
                    console.log(list1)
                    that.returnFlag = true;


//                    that.list = data.records.filter(function (element, i, self) {
//                        if (self[i].haveOverdue == '1' || self[i].haveOverdue == '2') {
//                            //逾期和快到期
//                            return true;
//                        }
//                    })
                });
                var obj = {
                    dialog: 'hidden'
                }
                prompt(JSON.stringify(obj))
            },
            isShowBtn: function (eName) {
                if ($.inArray(eName, this.rightOp) > -1) {
                    return true;
                } else {
                    return false;
                }
            },
            fmoney: function (s, n) {
                n = n > 0 && n <= 20 ? n : 2;
                s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
                var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1],
                    t = "";
                for (i = 0; i < l.length; i++) {
                    t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
                }
                return t.split("").reverse().join("") + "." + r;
            },
            //获取权限
            get_roleName: function () {
                var that = this;
                $.wyui.postMethod(urlConfig.newZXQReportForm.getRoleNameByUserId, {
                    "userId": that.searchParams.userId,
                }, function (data) {
                    that.roleName = data.records;

                }, true);

            },
            goDetail: function (type, item) {
                var obj = {
                    type: 'goDetail',
                    url: '/apply/accountReceivable/detailApp.html?id=' + item.id + "&pageType=look&userId=" + getUrlParamObj().userId,
                    id: item.id,
                    name: "应收详情",
                    screenType: '0',
                }
                prompt(JSON.stringify(obj))
            },
        },
        mounted: function () {
            var that = this;
            that.get_roleName();
            // that.roleName=getUrlParamObj().roleName
            // console.log(that.roleName);
            that.getList()
        }
    })
</script>
</body>
</html>